import 'package:flutter/material.dart';
import 'package:fluttertoast/fluttertoast.dart';
import '../shared/styles.dart';
import '../shared/colors.dart';
import '../shared/inputFields.dart';
import 'package:page_transition/page_transition.dart';
import './signIn_page.dart';
import './dash_board.dart';

class SignUpPage extends StatefulWidget {
  final String? pageTitle;

  SignUpPage({Key? key, this.pageTitle}) : super(key: key);

  @override
  _SignUpPageState createState() => _SignUpPageState();
}

class _SignUpPageState extends State<SignUpPage> {
  String name = "";

  @override
  Widget build(BuildContext context) {
    return Scaffold(
        appBar: AppBar(
          elevation: 0,
          backgroundColor: white,
          title: const Text('返回登陆',
              style: TextStyle(
                  color: Colors.grey, fontFamily: 'Poppins', fontSize: 15)),
          actions: <Widget>[
            TextButton(
              onPressed: () {
                // Navigator.of(context).pushReplacementNamed('/signin');
                Navigator.pushReplacement(
                    context,
                    PageTransition(
                        type: PageTransitionType.rightToLeft,
                        child: SignInPage()));
              },
              child: const Text('注册',
                  style: TextStyle(
                      color: Colors.black,
                      fontFamily: 'Poppins',
                      fontSize: 15)),
            )
          ],
        ),
        body: ListView(
          shrinkWrap: true,
          children: <Widget>[
            Container(
              padding: EdgeInsets.only(left: 18, right: 18),
              height: 360,
              width: double.infinity,
              decoration: authPlateDecoration,
              child: Stack(
                children: <Widget>[
                  Column(
                    mainAxisAlignment: MainAxisAlignment.start,
                    crossAxisAlignment: CrossAxisAlignment.start,
                    children: <Widget>[
                      const Text('欢迎来到 XJn!', style: h3),
                      const Text('Let\'s get started', style: taglineText),
                      // fryoTextInput('请输入姓氏'),
                      fryoTextInput('请输入名字', onChanged: (value) {
                        setState(() {
                          name = value;
                        });
                      }),
                      fryoEmailInput('请输入邮箱'),
                      fryoPasswordInput('请输入密码')
                    ],
                  ),
                  Positioned(
                    bottom: 15,
                    right: -15,
                    child: TextButton(
                      onPressed: () {
                        if (name.length < 2 || name.length > 5) {
                          Fluttertoast.showToast(msg: '账号长度必须在2-5之间');
                        } else {
                          Navigator.pushReplacement(
                              context,
                              PageTransition(
                                  type: PageTransitionType.rightToLeft,
                                  child: Dashboard(
                                    pageTitle: '',
                                  )));
                        }
                      },
                      style: TextButton.styleFrom(
                        foregroundColor: primaryColor,
                        shape: RoundedRectangleBorder(
                          borderRadius: BorderRadius.circular(4),
                        ),
                      ),
                      // color: primaryColor,
                      // padding: EdgeInsets.all(13),
                      // shape: CircleBorder(),
                      child: Icon(Icons.arrow_forward, color: Colors.black),
                    ),
                  )
                ],
              ),
            ),
          ],
        ));
  }
}
